function openWS() {
    var wsUri = "ws://localhost:9000/demo/server.php";
    websocket = new WebSocket(wsUri);

    websocket.onopen = function(ev) { // connection is open 
        console.log('Connection is istablished!');
        var msg = {
            type: 'open'
        };
        sendWS(msg);
    };
}

function sendWS(msg) {
    var baseUrl = $('#base-url').attr('href');
    $.ajax({
        url: baseUrl + '/auth/checkLogin',
        success: function(data) {
            var user = JSON.parse(data);
            var room = $('#room-id').val();
            if (user.status) {
                msg.id = user.id;
                msg.room = room;
                msg.role = 'teacher';
                websocket.send(JSON.stringify(msg));
            }
        }
    });
}